/**
 * Copyright(c): 2018 com.mjduan All rights reserved.
 * 项目名：sofarpcboot-learn
 * 注意：未经作者允许，不得外传
 */
package com.mjudan.project;

import com.alipay.common.tracer.core.SofaTracer;
import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext;
import com.alipay.common.tracer.core.context.trace.SofaTraceContext;
import com.alipay.common.tracer.core.holder.SofaTraceContextHolder;
import com.alipay.common.tracer.core.span.SofaTracerSpan;
import com.alipay.sofa.runtime.api.annotation.SofaService;
import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;

import org.springframework.stereotype.Service;

/**
 * @author dmj1161859184@126.com 2021-10-20 23:50
 * @version 1.0
 * @since 1.0
 */
@SofaService(interfaceType = AddressFacade.class, bindings = { @SofaServiceBinding(bindingType = "bolt") })
@Service
public class AddressServerImpl implements AddressFacade{

    @Override
    public String retrieveAddress() {
        SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext();

        SofaTracerSpan serverSpan = sofaTraceContext.pop();
        SofaTracerSpanContext sofaTracerSpanContext = serverSpan.getSofaTracerSpanContext();
        String traceId = sofaTracerSpanContext.getTraceId();
        String parentId = sofaTracerSpanContext.getParentId();
        SofaTracer sofaTracer = serverSpan.getSofaTracer();
        System.out.println("user consumer,traceId:{}"+traceId+",parentId:"+parentId);
        return "Street1";
    }
}
